﻿Imports OMANE.Common

<ModuleInfo()> _
Public Class DocModule
    Implements Common.IModule

    Private Shared _AppInstance As Common.Application
    Private Shared _DefaultIcone As String
    Private curvmdoc As ViewModelDocument
    Private tg As ObjectModel.ObservableCollection(Of Common.UI.IViewModelTabSection)
    Private vmdoc As ViewModelDocument
    Private vmdoc2 As ViewModelDocument
    Private vmdoc3 As ViewModelDocument

    Private ReadOnly Property Dependencies As System.Collections.Generic.IEnumerable(Of Common.ModuleReference) Implements Common.IModule.Dependencies
        Get
            Return Nothing
        End Get
    End Property

    Private Sub Load() Implements Common.IModule.Load

    End Sub

    Private Sub Reset(ByVal Application As Common.Application) Implements Common.IModule.Reset
        _AppInstance = Application

        _DefaultIcone = "pack://application:,,,/OMANE.Modules.Documentation;component/ebook16.png"

        Dim resourceDictionary As New Windows.ResourceDictionary With { _
            .Source = New Uri("/OMANE.Modules.Documentation;component/RessourcesTemplate.xaml", UriKind.Relative) _
        }

        _AppInstance.GetService(Of Common.UI.IUIService).AddResourceDictionary(resourceDictionary)

        Dim formation As Common.UI.V2ViewModelAccordeonMenuItem = DocModule._AppInstance.GetService(Of Common.UI.IUIService).V2ViewModelAccordeonMenu.Formation

        Dim group1 As New Common.UI.V2ViewModelTabGroup With { _
            .Title = "Etudes" _
        }
        Dim group2 As New Common.UI.V2ViewModelTabGroup With { _
            .Title = "Inventaires" _
        }
        Dim group3 As New Common.UI.V2ViewModelTabGroup With { _
            .Title = "Indicateurs" _
        }

        Me.tg = New ObjectModel.ObservableCollection(Of Common.UI.IViewModelTabSection)

        Dim group11 As New Common.UI.V2ViewModelTabGroup With { _
            .Title = "Taux Garantis", _
            .TabGroup = Me.tg _
        }

        Dim directoryName As String = IO.Path.GetDirectoryName(Me.GetType.Assembly.Location)
        Me.vmdoc = New ViewModelDocument(IO.Path.Combine(directoryName, "OMANEMU.xps"), "Manuel Utilisateur", False)
        Me.vmdoc2 = New ViewModelDocument(IO.Path.Combine(directoryName, "OMANECC.xps"), "Cahier Des Charges", False)
        Me.vmdoc3 = New ViewModelDocument(IO.Path.Combine(directoryName, "OMANERP.xps"), "Résultat des pesées", False)

        Me.vmdoc.PageNumber = 0
        group11.TabGroup.Add(Me.vmdoc)
        Me.vmdoc2.PageNumber = 0
        group11.TabGroup.Add(Me.vmdoc2)
        Me.vmdoc3.PageNumber = 0
        group11.TabGroup.Add(Me.vmdoc3)

        group1.Children.Add(group11)

        Dim group111 As New Common.UI.V2ViewModelTabGroup With { _
            .Title = "Manuel Utilisateur", _
            .Icone = _DefaultIcone, _
            .TabGroup = group11.TabGroup, _
            .TabSection = group11.TabGroup.Item(0) _
        }
        Dim group112 As New Common.UI.V2ViewModelTabGroup With { _
            .Title = "Cahier des Charges", _
            .Icone = _DefaultIcone, _
            .TabGroup = group11.TabGroup, _
            .TabSection = group11.TabGroup.Item(1) _
        }
        Dim group113 As New Common.UI.V2ViewModelTabGroup With { _
            .Title = "Résultat des pesées", _
            .Icone = _DefaultIcone, _
            .TabGroup = group11.TabGroup, _
            .TabSection = group11.TabGroup.Item(2) _
        }


        group11.Children.Add(group111)
        group11.Children.Add(group112)
        group11.Children.Add(group113)

        formation.Body.Root.Children.Add(group1)
        formation.Body.Root.Children.Add(group2)
        formation.Body.Root.Children.Add(group3)

        Dim str4 As String = IO.Path.Combine(directoryName, "OMANE MU CHAPITRES")
        Dim str As String = IO.Path.Combine(directoryName, "OMANE CC CHAPITRES")
        Me.curvmdoc = Me.vmdoc
        Me.Process(group111, XElement.Load(IO.Path.Combine(str4, "info.xml")))
        Me.curvmdoc = Me.vmdoc2
        Me.Process(group112, XElement.Load(IO.Path.Combine(str, "info.xml")))

        group111.Extras.Visible = False
        group112.Extras.Visible = False
        group113.Extras.Visible = False

    End Sub

    Private Sub Unload() Implements Common.IModule.Unload

    End Sub

    Private Sub Process(ByVal xnode As Common.UI.V2ViewModelTabGroup, ByVal x As XElement)
        Dim q = (From e In x.<Chapter> Select XE = e, Title = e.@Title, Page = CInt(e.@Page)).ToArray()

        Dim ts As New ObjectModel.ObservableCollection(Of Common.UI.IViewModelTabSection)

        For Each e In q
            Dim v = New ViewModelDocument(curvmdoc)
            v.Title = e.Title
            v.Icone = _DefaultIcone
            v.PageNumber = e.Page

            Dim n = New Common.UI.V2ViewModelTabGroup()
            n.Title = e.Title
            n.Icone = _DefaultIcone
            n.TabGroup = ts
            n.TabGroup.Add(v)
            n.TabSection = v

            xnode.Children.Add(n)


            'n.TabGroup = New ObjectModel.ObservableCollection(Of Common.UI.IViewModelTabSection)

            Process(n, e.XE)
        Next
    End Sub

End Class
